package com.guli.product.service.impl;

import com.guli.product.dao.PmsBrandDao;
import com.guli.product.dao.PmsCategoryDao;
import com.guli.product.entity.PmsBrandEntity;
import com.guli.product.entity.PmsCategoryEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.Query;

import com.guli.product.dao.PmsCategoryBrandRelationDao;
import com.guli.product.entity.PmsCategoryBrandRelationEntity;
import com.guli.product.service.PmsCategoryBrandRelationService;


@Service("pmsCategoryBrandRelationService")
public class PmsCategoryBrandRelationServiceImpl extends ServiceImpl<PmsCategoryBrandRelationDao, PmsCategoryBrandRelationEntity> implements PmsCategoryBrandRelationService {
    @SuppressWarnings("all")
    @Autowired
    PmsCategoryDao pmsCategoryDao;

    @SuppressWarnings("all")
    @Autowired
    PmsBrandDao brandDao;

    @SuppressWarnings("all")
    @Autowired
    PmsCategoryBrandRelationDao brandRelationDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PmsCategoryBrandRelationEntity> wrapper = new QueryWrapper<>();
        String brandId = (String) params.get("brandId");
        wrapper.eq("brand_id",brandId);
        IPage<PmsCategoryBrandRelationEntity> page = this.page(
                new Query<PmsCategoryBrandRelationEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<PmsCategoryBrandRelationEntity> datalist(Map<String, Object> params) {
        QueryWrapper<PmsCategoryBrandRelationEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("catelog_id",params.get("catId"));
        List<PmsCategoryBrandRelationEntity> pmsCategoryBrandRelationEntities = brandRelationDao.selectList(wrapper);

        return pmsCategoryBrandRelationEntities;
    }

    @Override
    public boolean save(PmsCategoryBrandRelationEntity entity) {
        PmsCategoryEntity categoryEntity = pmsCategoryDao.selectById(entity.getCatelogId());
        PmsBrandEntity brandEntity = brandDao.selectById(entity.getBrandId());
        entity.setBrandName(brandEntity.getName());
        entity.setCatelogName(categoryEntity.getName());
        return super.save(entity);
    }
}